package com.hsmpay.common.service.impl;

import com.hsmpay.common.dao.BaseDao;
import com.hsmpay.common.service.BaseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 服务基类
 *
 * @param <Entity>
 * @param <Query>
 * @author 颜铃璋
 *         建立时间：2012-11-22
 */
@Service("baseService")
public class BaseServiceSupport<Entity extends Serializable, Query extends Object> implements BaseService<Entity, Query> {
    @Resource(name = "baseDao")
    private BaseDao<Entity, Query> baseDao;


    /**
     * 添加 实体
     *
     * @param entity
     * @return
     * @throws Exception
     */
    public Query insertEntity(Entity entity) throws Exception {
        return baseDao.insertEntity(entity);
    }

    /**
     * 添加 实体
     *
     * @param sqlKey
     * @param entity
     * @return
     * @throws Exception
     */
    public Query insertEntity(String sqlKey, Entity entity) throws Exception {
        return baseDao.insertEntity(sqlKey, entity);
    }

    //-----------------------------------------------

    /**
     * 修改 实体
     *
     * @param entity
     * @return
     * @throws Exception
     */
    public int updateEntity(Entity entity) throws Exception {
        return baseDao.updateEntity(entity);
    }

    /**
     * 修改 实体
     *
     * @param sqlKey
     * @param entity
     * @return
     * @throws Exception
     */
    public int updateEntity(String sqlKey, Entity entity) throws Exception {
        return baseDao.updateEntity(sqlKey, entity);
    }

    //----------------------------------------------

    /**
     * 删除 实体
     *
     * @param entity
     * @return
     * @throws Exception
     */
    public int deleteEntity(Entity entity) throws Exception {
        return baseDao.deleteEntity(entity);
    }

    /**
     * 删除 实体  根据id
     *
     * @param entityClass
     * @param query
     * @return
     * @throws Exception
     */
    public int deleteEntity(Class<Entity> entityClass, Query query) throws Exception {
        return baseDao.deleteEntity(entityClass, query);
    }

    /**
     * 删除 实体
     *
     * @param entity
     * @return
     * @throws Exception
     */
    public int deleteEntity(String sqlKey, Entity entity) throws Exception {
        return baseDao.deleteEntity(sqlKey, entity);
    }

    //----------------------------------------

    /**
     * 根据实体参数查找单个数据
     *
     * @return
     * @throws Exception
     */
    public Entity searchEntity(Entity entity) throws Exception {
        return baseDao.searchEntity(entity);
    }

    /**
     * 查询 实体
     *
     * @param entity
     * @return
     * @throws Exception
     */
    public Entity searchEntity(String sqlKey, Entity entity) throws Exception {
        return baseDao.searchEntity(sqlKey, entity);
    }

    //----------------------------------------

    /**
     * introduce (根据Id查找)
     *
     * @param query
     * @return
     * @throws Exception
     */
    public Entity searchEntityById(Class<Entity> entityClass, Query query) throws Exception {
        return baseDao.searchEntityById(entityClass, query);
    }

    /**
     * 查询 实体列表
     *
     * @return
     * @throws Exception
     */
    public List<Entity> searchEntityList(Entity entity) throws Exception {
        return baseDao.searchEntityList(entity);
    }

    /**
     * 查询 实体列表
     *
     * @param entity
     * @return
     * @throws Exception
     */
    public List<Entity> searchEntityList(String sqlKey, Entity entity) throws Exception {
        return baseDao.searchEntityList(sqlKey, entity);
    }

    //-----------------------------------------

    /**
     * 查询总数
     *
     * @throws Exception
     */
    public int getEntityCount(Entity entity) throws Exception {
        return baseDao.getEntityCount(entity);
    }

    /**
     * 查询总数
     *
     * @param sqlMap
     * @param query
     * @throws Exception
     */
    public int getEntityCount(String sqlMap, Query query) throws Exception {
        return baseDao.getEntityCount(sqlMap, query);
    }
}
